package com.qf.controller;

import com.netflix.discovery.EurekaClient;
import com.qf.feign.SearchFeign;
import com.qf.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private EurekaClient eurekaClient;
    @Autowired
    private SearchFeign searchFeign;

    @RequestMapping("/consumer")
    public String test(){
//        InstanceInfo info = eurekaClient.getNextServerFromEureka("QF-SEARCH", false);
//        String url = info.getHomePageUrl();
//        System.out.println("======url========"+url);
        String str = restTemplate.getForObject( "http://QF-SEARCH/search/test", String.class);
        System.out.println("======str===="+str);
        return str;
    }
    @RequestMapping("/testfeign")
    public String feign(){
        String str = searchFeign.test();
        System.out.println("========"+str);
        return str;
    }
    @RequestMapping("/findUser")
    public User findUser(){
        User user = searchFeign.findById(1);
        return user;
    }
}
